package com.lyy.photovoltaic.controller;

import com.lyy.photovoltaic.beans.Staffs;
import com.lyy.photovoltaic.common.vo.ResultVO;
import com.lyy.photovoltaic.mapper.StaffsMapper;
import com.lyy.photovoltaic.service.AdministratorService;
import com.lyy.photovoltaic.service.StaffsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/staffs")
@Api(value = "员工管理接口", tags = "员工管理")
public class StaffsController {
    @Autowired
    StaffsService staffsService;

    @ApiOperation(value = "员工登录接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string", name = "sid", value = "员工登录账号", required = true),
            @ApiImplicitParam(dataType = "string", name = "pwd", value = "员工登录密码", required = true)
    })
    @PostMapping("/login")
    public ResultVO staffsLogin(@RequestParam("sid") String sId, @RequestParam("pwd") String pwd) {
        ResultVO resultVO = staffsService.staffsLogin(sId, pwd);
        return resultVO;
    }

    @PostMapping("/regist")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string", name = "sid", value = "员工注册账号", required = true),
            @ApiImplicitParam(dataType = "string", name = "pwd", value = "员工注册密码", required = true)
    })
    @ApiOperation(value = "管理员注册接口")
    public ResultVO staffsRegist(@RequestParam("sid") String sId, @RequestParam("pwd") String pwd) {
        ResultVO resultVO = staffsService.staffsRegist(sId, pwd);
        return resultVO;
    }
    @PostMapping("/addStaffs")
    @ApiOperation(value = "管理员注册接口")
    public ResultVO addStaffs(@RequestBody Staffs staff) {
        ResultVO resultVO = staffsService.addStaffs(staff);
        return resultVO;
    }
    @GetMapping("/allStaffs")
    public ResultVO allStaffs(){
        ResultVO resultVO = staffsService.AllStaffs();
        return resultVO;
    }
    @GetMapping("/{staffId}")
    @ApiImplicitParam(dataType = "string", name = "staffId", value = "要查询的员工id", required = true)
    public ResultVO findStaffById(@PathVariable("staffId") String sId){
        ResultVO resultVO = staffsService.findStaffById(sId);
        return resultVO;
    }
    @PutMapping("/{staffId}")
    @ApiImplicitParam(dataType = "string", name = "staffId", value = "要更新的员工id", required = true)
    public ResultVO updateStaffById(@RequestBody Staffs staff){
        ResultVO resultVO = staffsService.updateStaffById(staff);
        return resultVO;
    }
    @DeleteMapping("/{staffId}")
    @ApiImplicitParam(dataType = "string", name = "staffId", value = "要更新的员工id", required = true)
    public ResultVO deleteStaffById(@PathVariable("staffId") String sId){
        ResultVO resultVO = staffsService.deleteStaffById(sId);
        return resultVO;
    }
}
